//
//  Data.swift
//  SwiftUI-CTao
//
//  Created by 涛 on 2019/9/19.
//  Copyright © 2019 涛. All rights reserved.
//
import Foundation
import CoreLocation
import UIKit
import SwiftUI

let noteData: [ContentModel] = load("contentData.json")

func load<T: Decodable>(_ filename: String, as type: T.Type = T.self) -> T {
    let data : Data
    
    guard let file = Bundle.main.url(forResource: filename, withExtension: nil) else {
        fatalError("没有找到\(filename)文件")
    }
    
    do {
        data = try Data(contentsOf: file)
    } catch {
        fatalError("无法读取\(filename)文件:\n\(error)")
    }
        
    do {
        let decoder = JSONDecoder()
        
        return try decoder.decode(T.self, from: data)
    } catch  {
        fatalError("无法解析\(filename)文件:\n\(error)")
    }
}
